package com.woniuxy.redenvelope.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.request.ResponseResult;


import com.woniuxy.redenvelope.service.KillRedEnvelopeSerice;

import com.woniuxy.redenvelope.vo.AddKillVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/killredEnvelope")
public class KillRedEnvelopeController {

    @Resource
    private KillRedEnvelopeSerice redEnvelopeSerice;
    @GetMapping("/findAll")
    public ResponseResult<PageInfo<AddKillVo>> findAll(Integer currentPage, Integer pageSize, String name){
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.findAll(currentPage,pageSize,name));
    }

    @PostMapping("/addkill")
    public ResponseResult<Boolean> add(@RequestBody AddKillVo addKillVo){
        log.debug(addKillVo.toString());
        // 获取添加秒杀活动用户id
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.add(addKillVo));
    }

    @PutMapping("/edit")
    public ResponseResult<Boolean> edit(@RequestBody AddKillVo addKillVo){
            return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.edit(addKillVo));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id")Integer id){
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.delete(id));
    }

/*    @GetMapping("/list")
    public ResponseResult<List<AddKillVo>> list(){
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.list());
    }*/

    @PostMapping("/pay/{rid}")
    public ResponseResult<Boolean> pay(@PathVariable("rid")Integer rid){
        boolean res = redEnvelopeSerice.pay(rid);
        return new ResponseResult<>(ResponseResult.OK,res);


    }

    @GetMapping("/getKillRedEnvelope")
    public ResponseResult<PageInfo<AddKillVo>> getKillRedEnvelope(Integer currentPage, Integer pageSize, String name){
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.getKillRedEnvelope(currentPage,pageSize,name));
    }

    @PutMapping("/editKillRedEnvelope")
    public ResponseResult<Boolean> editKillRedEnvelope(@RequestBody AddKillVo addKillVo){
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.editKillRedEnvelope(addKillVo));
    }

    @PutMapping("/stopKillFromRedis/{id}")
    public ResponseResult<Boolean> stopKillFromRedis(@PathVariable("id")Integer id){
        return new ResponseResult<>(ResponseResult.OK,redEnvelopeSerice.stopKillFromRedis(id));
    }
}
